package com.cyy.service;

import com.cyy.entity.CreateOrderEntity;
import com.cyy.operation.request.HTTP;
import com.cyy.utils.Common;
import io.restassured.http.Method;
import io.restassured.response.Response;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j
@Data
public class HttpService {
    String baseURL = System.getProperty("BaseURL");

    @Autowired
    HTTP http;
    @Autowired
    Common common;


    public Response createOder(CreateOrderEntity orderEntity) {
        Map map = common.entity2map(orderEntity);
        return createOder(map);
    }

    public Response createOder(Map<Object, Object> payload) {
        // 替换参数
        payload.keySet().forEach((key -> payload.put(key, common.replace(payload.get(key).toString()))));
        http.setBaseURI(baseURL);
        http.setHeaders("Content-Type", "application/json");
        http.setMethod(Method.POST);
        http.setPath("/api/misc/test/autoCreateAndDispatchOrder");
        http.setPayload(payload);

        Response response = http.send();

        return response;
    }

}
